

import {getCheckNewVersionStatusCallback} from "./i_idl_ota_service";
import {setDownloadTaskStatusCallback} from "./i_idl_ota_service";
import IIdlOtaService from "./i_idl_ota_service";
import rpc from "@ohos.rpc";

export default class IdlOtaServiceStub extends rpc.RemoteObject implements IIdlOtaService {
    constructor(des: string) {
        super(des);
    }

    async onRemoteMessageRequest(code: number, data, reply, option): Promise<boolean> {
        console.log("onRemoteRequest called, code = " + code);
        switch(code) {
            case IdlOtaServiceStub.COMMAND_GET_CHECK_NEW_VERSION_STATUS: {
                await this.getCheckNewVersionStatus((errCode, returnValue) => {
                    reply.writeInt(errCode);
                    if (errCode == 0) {
                        reply.writeInt(returnValue);
                    }
                });
                return true;
            }
            case IdlOtaServiceStub.COMMAND_SET_DOWNLOAD_TASK_STATUS: {
                let _status = data.readInt();
                this.setDownloadTaskStatus(_status, (errCode) => {
                    reply.writeInt(errCode);
                });
                return true;
            }
            default: {
                console.log("invalid request code" + code);
                break;
            }
        }
        return false;
    }
    
    getCheckNewVersionStatus(callback: getCheckNewVersionStatusCallback): void{}
    setDownloadTaskStatus(status: number, callback: setDownloadTaskStatusCallback): void{}

    static readonly COMMAND_GET_CHECK_NEW_VERSION_STATUS = 1;
    static readonly COMMAND_SET_DOWNLOAD_TASK_STATUS = 2;
}

